<template>
  <el-main>
  <div class="block">
              <span class="demonstration">月</span>
              <el-date-picker v-model="value1" type="month" placeholder="选择月" value-format="yyyy-MM">
              </el-date-picker>
          </div>
          <div>
              <el-button round @click="sum">统计</el-button>
          </div>
          <el-table :data="total">
              <el-table-column label="总计" width="140" prop="totalAmount"></el-table-column>
          </el-table>
</el-main>
</template>
  
<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
<script>
export default {
  name: "Sum",
  data() {
    return {
      user:{},
      total:[],
      value1:""
    };
  },
  methods: {
    toUpload() {
      this.$router.push({ path: "/upload" });
    },
    toMonth() {
      this.$router.push({ path: "/month" });
    },
    toSum() {
      this.$router.push({ path: "/sum" });
    },
    toMain() {
      this.$router.push({ path: '/main' })
    },
    logout() {
      this.$axios({
        method: "get",
        url: "/user/out",
        headers: {
          token: sessionStorage.getItem("token"),
        },
      }).then((res) => {
        if (res.data.code == 0) {
          sessionStorage.clear();
          this.$router.replace({ path: "/" });
        }
      });
    },
    getUser() {
      this.$axios({
        method: "get",
        url: '/user/get',
        headers: {
          token: sessionStorage.getItem("token"),
        }
      }).then((res) => {
        if (res.data.code == 0) {
          this.user = res.data.data
        }
      })
    },
    sum(){
      this.$axios({
        method: "get",
        url: "/invoice/sum/month/" + this.value1,
        headers: {
          token: sessionStorage.getItem("token"),
        }
      }).then((res) =>{
        if(res.data.code == 0){
          this.total.push(JSON.parse(res.data.data))
        }
      })
    }
  },
  mounted(){
    this.getUser();
  }
};
</script>